package com.example.finalssm.Controller;

import com.example.finalssm.mapper.CommentMapper;
import com.example.finalssm.mapper.QuestionMapper;
import com.example.finalssm.mapper.ReplyMapper;
import com.example.finalssm.utils.MybatisUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/blogger")
public class CommentController {
    @RequestMapping("/comment")
    @ResponseBody
    public String comment(String comment, String CommentId, HttpSession session){
        Map<String,String> map=new HashMap<>();
        map.put("userId",(String) session.getAttribute("userId"));
        map.put("comment",comment);
        map.put("commentId",CommentId);
        int i = MybatisUtils.getSqlSession().getMapper(CommentMapper.class).addComment(map);
        if(i==1)
            return "评论成功";
        else return "评论失败";
    }
    //用户删除问题
    @RequestMapping("/deleteComment")
    @ResponseBody
    public  String deleteAnswer(@RequestParam("GPS_commentId") String id){
        int j=MybatisUtils.getSqlSession().getMapper(CommentMapper.class).deleteComment02(id);
        if(j==1)
            return "删除成功";
        else return "删除失败";
    }
}
